package com.jianhua.backend.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jianhua.backend.domain.dto.ExceptionRecordsDto;
import com.jianhua.backend.domain.entity.ExceptionRecords;
import com.jianhua.backend.domain.vo.PageVo;
import com.jianhua.backend.mapper.ExceptionRecordsMapper;
import com.jianhua.backend.mapper.UserMapper;
import com.jianhua.backend.service.ExceptionRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 记录订单处理过程中的异常情况 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-07-02
 */
@Service
public class ExceptionRecordsServiceImpl extends ServiceImpl<ExceptionRecordsMapper, ExceptionRecords> implements ExceptionRecordsService {

    @Autowired
    private ExceptionRecordsMapper exceptionRecordsMapper;


    @Override
    public PageVo<ExceptionRecords> listExceptionRecords(ExceptionRecordsDto exceptionRecordsDto) {
        Page<ExceptionRecords> page = new Page<>(exceptionRecordsDto.getPage(), exceptionRecordsDto.getSize());
        LambdaQueryWrapper<ExceptionRecords> queryWrapper = new LambdaQueryWrapper<>();
        if(exceptionRecordsDto.getOrderId() != null){
            queryWrapper.eq(ExceptionRecords::getOrderId, exceptionRecordsDto.getOrderId());
        }
        if(exceptionRecordsDto.getStatus() != null){
            queryWrapper.eq(ExceptionRecords::getStatus, exceptionRecordsDto.getStatus());
        }
        Page<ExceptionRecords> paged = page(page, queryWrapper);
        long total = paged.getTotal();
        Integer count = Integer.valueOf((int) total);
        List<ExceptionRecords> records = paged.getRecords();
        return new PageVo<>(count, records);
    }

    @Override
    public void updateExceptionRecords(ExceptionRecords exceptionRecords) {
        exceptionRecordsMapper.updateById(exceptionRecords);
    }
}
